<?php
class ZthangsController extends AppController {

	var $name = 'Zthangs';

	function index() {
		$this->Zthang->recursive = 0;
		$this->set('zthangs', $this->paginate());
	}
    
    function chitieutt($donvi=null) {
		$this->Zthang->recursive = 0;
		$this->set('zthangs', $this->paginate(array('donvi_id'=>$donvi)));
        $this->set(compact('donvi'));
	}
    
    function chitieucn($donvi=null) {
        $tendv=$this->Zthang->query("select tendv from donvis where donvis.id=".$donvi);
		$this->Zthang->recursive = 0;
		$this->set('zthangs', $this->paginate(array('donvi_id'=>$donvi)));
        $this->set(compact('donvi','tendv'));
	}
    
    

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid zthang', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('zthang', $this->Zthang->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Zthang->create();
			if ($this->Zthang->save($this->data)) {
				$this->Session->setFlash(__('The zthang has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The zthang could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid zthang', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Zthang->save($this->data)) {
				$this->Session->setFlash(__('The zthang has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The zthang could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Zthang->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for zthang', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Zthang->delete($id)) {
			$this->Session->setFlash(__('Zthang deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Zthang was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
